package testcase;


import static org.junit.Assert.assertEquals;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileWriter;
import java.io.PrintStream;
import java.lang.reflect.Method;
import java.text.*;
import java.util.*;

import impl.cityuImpl;

import org.jsoup.Jsoup;
import org.jsoup.nodes.*;
import org.jsoup.select.Elements;
import org.junit.*;

import dataobj.CourseTO;

public class TestCityUImpl{
	
	private cityuImpl impl;
	
	@Before
	public void setUp(){
		impl = new cityuImpl();
	}

	@Test
	public void testGetWeekDayByChar() throws Exception{
		Method method = cityuImpl.class.getDeclaredMethod("getWeekDayByChar", String.class);
		method.setAccessible(true);
		assertEquals(method.invoke(impl, "U"), 1);
	}

	@Test
	public void testGetWrongWeekDayByChar() throws Exception{
		Method method = cityuImpl.class.getDeclaredMethod("getWeekDayByChar", String.class);
		method.setAccessible(true);
		assertEquals(method.invoke(impl, "A"), -1);
	}
	
	//Test CorrectTime method
	
	//Test when there is no increase of date
	@Test
	public void testCorrectTime1() throws Exception{
		SimpleDateFormat tf = new SimpleDateFormat("MMM dd, yyyy hh:mm a", Locale.US);
		tf.setTimeZone(TimeZone.getTimeZone("Asia/Hong_Kong"));
		Date inputDate = tf.parse("NOV 25, 1980 12:25 am");
		Date outputDate = tf.parse("NOV 25, 1980 12:25 am");
		
		Method method = cityuImpl.class.getDeclaredMethod("correctTime", Date.class, Integer.class);
		method.setAccessible(true);
		assertEquals(method.invoke(impl, inputDate, 3), outputDate);
	}
	
	//Test when there is increase of date
	@Test
	public void testCorrectTime2() throws Exception{
		SimpleDateFormat tf = new SimpleDateFormat("MMM dd, yyyy hh:mm a", Locale.US);
		tf.setTimeZone(TimeZone.getTimeZone("Asia/Hong_Kong"));
		Date inputDate = tf.parse("NOV 25, 1980 12:25 am");
		Date outputDate = tf.parse("NOV 30, 1980 12:25 am");
		
		Method method = cityuImpl.class.getDeclaredMethod("correctTime", Date.class, Integer.class);
		method.setAccessible(true);
		assertEquals(method.invoke(impl, inputDate, 1), outputDate);
	}
	
	//Test prepareTime method
	
	//Test with pre-condition: CorrectTime is correct
	//Test everything works normally
	@Test
	public void testPrepareTime1() throws Exception{
		String inputDate = "NOV 25, 1980 12:25 am";
		String inputTime = "12:25 am";
		int weekDay = 1;
		
		SimpleDateFormat tf = new SimpleDateFormat("MMM dd, yyyy hh:mm a", Locale.US);
		tf.setTimeZone(TimeZone.getTimeZone("Asia/Hong_Kong"));
		Date outputDate = tf.parse("NOV 30, 1980 12:25 am");
		
		Method method = cityuImpl.class.getDeclaredMethod("prepareTime", String.class, String.class, Integer.class);
		method.setAccessible(true);
		assertEquals(method.invoke(impl, inputDate, inputTime, weekDay), outputDate);
	}
	
	//Test with pre-condition: CorrectTime is correct
	//Test time parse wrongly
	@Test(expected=Exception.class)
	public void testPrepareTime2() throws Exception{
		String inputDate = "NOV 25 1980 12:25 am";
		String inputTime = "12:25 am";
		int weekDay = 1;
		
		Method method = cityuImpl.class.getDeclaredMethod("prepareTime", String.class, String.class, Integer.class);
		method.setAccessible(true);
		method.invoke(impl, inputDate, inputTime, weekDay);
		
	}
	
	
	//Test getCourseTO method
	
	//Test with pre-condition: All the previous functions are correct
	//Test everything works normally
	@Test
	public void testGetCourseTO1() throws Exception{
		SimpleDateFormat tf = new SimpleDateFormat("MMM dd, yyyy hh:mm:ss a", Locale.US);
		tf.setTimeZone(TimeZone.getTimeZone("Asia/Hong_Kong"));
		
		CourseTO outputCourse = new CourseTO();
		outputCourse.setName("a");
		outputCourse.setCode("e");
		outputCourse.setSession("e");
		outputCourse.setCrn("e");
		outputCourse.setInstructor("e");
		outputCourse.setCredits(1.0);
		outputCourse.setVenue("abcd");
		outputCourse.setStartTime(tf.parse("NOV 25, 1980 12:25:00 am"));
		outputCourse.setEndTime(tf.parse("NOV 25, 1980 7:25:00 pm"));
		outputCourse.setStartDate(tf.parse("NOV 25, 1980 0:0:0 am"));
		outputCourse.setEndDate(tf.parse("NOV 25, 1980 11:59:59 pm"));
		outputCourse.setWeekDay(3);
		
		String[] inputTime = {"12:25 am", "7:25 pm"};
		String[] inputDate = {"NOV 25, 1980", "NOV 25, 1980"};
		Method method = cityuImpl.class.getDeclaredMethod("getCourseTO", String.class, String.class, String.class, 
				String.class, String.class, Double.class, inputTime.getClass(), inputDate.getClass(), String.class, String.class);
		method.setAccessible(true);
		CourseTO result = (CourseTO) method.invoke(impl, "a", "e", "e", "e", "e", 1.0, inputTime, inputDate, "T", "abcd");
		
		assertEquals(result.getName(), outputCourse.getName());
		assertEquals(result.getCode(), outputCourse.getCode());
		assertEquals(result.getSession(), outputCourse.getSession());
		assertEquals(result.getCrn(), outputCourse.getCrn());
		assertEquals(result.getInstructor(), outputCourse.getInstructor());
		assertEquals(result.getCredits(), outputCourse.getCredits());
		assertEquals(result.getVenue(), outputCourse.getVenue());
		assertEquals(result.getStartTime(), outputCourse.getStartTime());
		assertEquals(result.getEndTime(), outputCourse.getEndTime());
		assertEquals(result.getStartDate(), outputCourse.getStartDate());
		assertEquals(result.getEndDate(), outputCourse.getEndDate());
		assertEquals(result.getWeekDay(), outputCourse.getWeekDay());
	}
	
	//Test with pre-condition: All the previous functions are correct
	//Test error with null
	@Test
	public void testGetCourseTO2() throws Exception{
		String[] inputTime = {"12:25 am", "7:25 pm"};
		String[] inputDate = {"NOV 25 1980", "NOV 25, 1980"};
		Method method = cityuImpl.class.getDeclaredMethod("getCourseTO", String.class, String.class, String.class, 
				String.class, String.class, Double.class, inputTime.getClass(), inputDate.getClass(), String.class, String.class);
		method.setAccessible(true);
		assertEquals(method.invoke(impl, "a", "e", "e", "e", "e", 1.0, inputTime, inputDate, "T", "abcd"), null);
	}

	
	//Test getCoursesByElements method
	
	//Test with pre-condition: All the previous functions are correct
	@Test
	public void testGetCoursesByElements1() throws Exception{
		String html = "<TABLE CLASS=\"datadisplaytable\" SUMMARY=\"This layout table is used to present the schedule course detail\" cellspacing=\"0\" cellpadding=2><CAPTION class=\"captiontext\">Software Engineering Practice - CS 3343 - CB1</CAPTION><TR><TH COLSPAN=\"2\" CLASS=\"ddlabel\" scope=\"row\" >Associated Term:</TH><TD CLASS=\"dddefault\">Semester A 2014/15</TD></TR><TR><TH COLSPAN=\"2\" CLASS=\"ddlabel\" scope=\"row\" ><ACRONYM title=\"Course Reference Number\">CRN</ACRONYM>:</TH><TD CLASS=\"dddefault\">45542</TD></TR><TR><TH COLSPAN=\"2\" CLASS=\"ddlabel\" scope=\"row\" >Status:</TH><TD CLASS=\"dddefault\">Registered on Jul 10, 2014</TD></TR><TR><TH COLSPAN=\"2\" CLASS=\"ddlabel\" scope=\"row\" >Assigned Instructor:</TH><TD CLASS=\"dddefault\">Wai Jacky KEUNG</TD></TR><TR><TH COLSPAN=\"2\" CLASS=\"ddlabel\" scope=\"row\" >Grade Mode:</TH><TD CLASS=\"dddefault\">Letter grade</TD></TR><TR><TH COLSPAN=\"2\" CLASS=\"ddlabel\" scope=\"row\" >Credits:</TH><TD CLASS=\"dddefault\"> 3.000</TD></TR><TR><TH COLSPAN=\"2\" CLASS=\"ddlabel\" scope=\"row\" >Level:</TH><TD CLASS=\"dddefault\">Bachelor's Degree</TD></TR><TR><TH COLSPAN=\"2\" CLASS=\"ddlabel\" scope=\"row\" >Campus:</TH><TD CLASS=\"dddefault\">Main Campus</TD></TR></TABLE><TABLE CLASS=\"datadisplaytable\" SUMMARY=\"This table lists the scheduled meeting times and assigned instructors for this class..\" cellspacing=\"0\" cellpadding=2><CAPTION class=\"captiontext\">Scheduled Meeting Times</CAPTION><TR><TH CLASS=\"ddheader\" scope=\"col\" >Type</TH><TH CLASS=\"ddheader\" scope=\"col\" >Time</TH><TH CLASS=\"ddheader\" scope=\"col\" >Days</TH><TH CLASS=\"ddheader\" scope=\"col\" >Where</TH><TH CLASS=\"ddheader\" scope=\"col\" >Date Range</TH><TH CLASS=\"ddheader\" scope=\"col\" >Schedule Type</TH><TH CLASS=\"ddheader\" scope=\"col\" >Instructors</TH></TR><TR><TD CLASS=\"dddefault\">Class</TD><TD CLASS=\"dddefault\">2:00 pm - 2:50 pm</TD><TD CLASS=\"dddefault\">F</TD><TD CLASS=\"dddefault\">Academic 1 LT-7</TD><TD CLASS=\"dddefault\">Sep 01, 2014 - Nov 29, 2014</TD><TD CLASS=\"dddefault\">First room</TD><TD CLASS=\"dddefault\">Wai Jacky KEUNG (<ABBR title=\"Primary\">P</ABBR>)</TD></TR></TABLE>";
		Document doc = Jsoup.parse(html);
		Elements blocks = doc.getElementsByClass("datadisplaytable");
		Element courseDetail = blocks.get(0);
		Element courseTime = blocks.get(1);
		
		String outputString = "Code: CS 3343 - CB1\n"
				+"Name: Software Engineering Practice\n"
				+"Instructor: Wai Jacky KEUNG\n"
				+"Venue: Academic 1 LT-7\n"
				+"Time: 02:00 PM - 02:50 PM\n"
				+"Weekday: Friday\n";
		
		Method method = cityuImpl.class.getDeclaredMethod("getCourseByElements", Element.class, Element.class);
		method.setAccessible(true);
		ArrayList<CourseTO> result = (ArrayList<CourseTO>) method.invoke(impl, courseDetail, courseTime);
		assertEquals(result.get(0).toString(), outputString);
	}
	
	//Test when there is no time
	@Test
	public void testGetCoursesByElements2() throws Exception{
		String html = "<TABLE CLASS=\"datadisplaytable\" SUMMARY=\"This layout table is used to present the schedule course detail\" cellspacing=\"0\" cellpadding=2><CAPTION class=\"captiontext\">Software Engineering Practice - CS 3343 - CB1</CAPTION><TR><TH COLSPAN=\"2\" CLASS=\"ddlabel\" scope=\"row\" >Associated Term:</TH><TD CLASS=\"dddefault\">Semester A 2014/15</TD></TR><TR><TH COLSPAN=\"2\" CLASS=\"ddlabel\" scope=\"row\" ><ACRONYM title=\"Course Reference Number\">CRN</ACRONYM>:</TH><TD CLASS=\"dddefault\">45542</TD></TR><TR><TH COLSPAN=\"2\" CLASS=\"ddlabel\" scope=\"row\" >Status:</TH><TD CLASS=\"dddefault\">Registered on Jul 10, 2014</TD></TR><TR><TH COLSPAN=\"2\" CLASS=\"ddlabel\" scope=\"row\" >Assigned Instructor:</TH><TD CLASS=\"dddefault\">Wai Jacky KEUNG</TD></TR><TR><TH COLSPAN=\"2\" CLASS=\"ddlabel\" scope=\"row\" >Grade Mode:</TH><TD CLASS=\"dddefault\">Letter grade</TD></TR><TR><TH COLSPAN=\"2\" CLASS=\"ddlabel\" scope=\"row\" >Credits:</TH><TD CLASS=\"dddefault\"> 3.000</TD></TR><TR><TH COLSPAN=\"2\" CLASS=\"ddlabel\" scope=\"row\" >Level:</TH><TD CLASS=\"dddefault\">Bachelor's Degree</TD></TR><TR><TH COLSPAN=\"2\" CLASS=\"ddlabel\" scope=\"row\" >Campus:</TH><TD CLASS=\"dddefault\">Main Campus</TD></TR></TABLE><TABLE CLASS=\"datadisplaytable\" SUMMARY=\"This table lists the scheduled meeting times and assigned instructors for this class..\" cellspacing=\"0\" cellpadding=2><CAPTION class=\"captiontext\">Scheduled Meeting Times</CAPTION><TR><TH CLASS=\"ddheader\" scope=\"col\" >Type</TH><TH CLASS=\"ddheader\" scope=\"col\" >Time</TH><TH CLASS=\"ddheader\" scope=\"col\" >Days</TH><TH CLASS=\"ddheader\" scope=\"col\" >Where</TH><TH CLASS=\"ddheader\" scope=\"col\" >Date Range</TH><TH CLASS=\"ddheader\" scope=\"col\" >Schedule Type</TH><TH CLASS=\"ddheader\" scope=\"col\" >Instructors</TH></TR><TR><TD CLASS=\"dddefault\">Class</TD><TD CLASS=\"dddefault\">TBA</TD><TD CLASS=\"dddefault\">F</TD><TD CLASS=\"dddefault\">Academic 1 LT-7</TD><TD CLASS=\"dddefault\">Sep 01, 2014 - Nov 29, 2014</TD><TD CLASS=\"dddefault\">First room</TD><TD CLASS=\"dddefault\">Wai Jacky KEUNG (<ABBR title=\"Primary\">P</ABBR>)</TD></TR></TABLE>";
		Document doc = Jsoup.parse(html);
		Elements blocks = doc.getElementsByClass("datadisplaytable");
		Element courseDetail = blocks.get(0);
		Element courseTime = blocks.get(1);
		
		Method method = cityuImpl.class.getDeclaredMethod("getCourseByElements", Element.class, Element.class);
		method.setAccessible(true);
		ArrayList<CourseTO> result = (ArrayList<CourseTO>) method.invoke(impl, courseDetail, courseTime);
		assertEquals(result.size(), 0);
	}
	
	//Test GetCourses method
	//Test with pre-condition: all the previous functions are correct
	@Test
	public void testGetCourses() throws Exception{
		String html = "<TABLE CLASS=\"datadisplaytable\" SUMMARY=\"This layout table is used to present the schedule course detail\" cellspacing=\"0\" cellpadding=2><CAPTION class=\"captiontext\">Sci, Tech & Soc for Computing - AIS 3301 - C61</CAPTION><TR><TH COLSPAN=\"2\" CLASS=\"ddlabel\" scope=\"row\" >Associated Term:</TH><TD CLASS=\"dddefault\">Semester A 2014/15</TD></TR><TR><TH COLSPAN=\"2\" CLASS=\"ddlabel\" scope=\"row\" ><ACRONYM title=\"Course Reference Number\">CRN</ACRONYM>:</TH><TD CLASS=\"dddefault\">43870</TD></TR><TR><TH COLSPAN=\"2\" CLASS=\"ddlabel\" scope=\"row\" >Status:</TH><TD CLASS=\"dddefault\">Registered on Jul 10, 2014</TD></TR><TR><TH COLSPAN=\"2\" CLASS=\"ddlabel\" scope=\"row\" >Assigned Instructor:</TH><TD CLASS=\"dddefault\">Chris FUNG</TD></TR><TR><TH COLSPAN=\"2\" CLASS=\"ddlabel\" scope=\"row\" >Grade Mode:</TH><TD CLASS=\"dddefault\">Letter grade</TD></TR><TR><TH COLSPAN=\"2\" CLASS=\"ddlabel\" scope=\"row\" >Credits:</TH><TD CLASS=\"dddefault\"> 3.000</TD></TR><TR><TH COLSPAN=\"2\" CLASS=\"ddlabel\" scope=\"row\" >Level:</TH><TD CLASS=\"dddefault\">Bachelor's Degree</TD></TR><TR><TH COLSPAN=\"2\" CLASS=\"ddlabel\" scope=\"row\" >Campus:</TH><TD CLASS=\"dddefault\">Main Campus</TD></TR></TABLE><TABLE CLASS=\"datadisplaytable\" SUMMARY=\"This table lists the scheduled meeting times and assigned instructors for this class..\" cellspacing=\"0\" cellpadding=2><CAPTION class=\"captiontext\">Scheduled Meeting Times</CAPTION><TR><TH CLASS=\"ddheader\" scope=\"col\" >Type</TH><TH CLASS=\"ddheader\" scope=\"col\" >Time</TH><TH CLASS=\"ddheader\" scope=\"col\" >Days</TH><TH CLASS=\"ddheader\" scope=\"col\" >Where</TH><TH CLASS=\"ddheader\" scope=\"col\" >Date Range</TH><TH CLASS=\"ddheader\" scope=\"col\" >Schedule Type</TH><TH CLASS=\"ddheader\" scope=\"col\" >Instructors</TH></TR><TR><TD CLASS=\"dddefault\">Class</TD><TD CLASS=\"dddefault\">6:30 pm - 8:20 pm</TD><TD CLASS=\"dddefault\">M</TD><TD CLASS=\"dddefault\">Academic 1 LT-6</TD><TD CLASS=\"dddefault\">Sep 01, 2014 - Nov 29, 2014</TD><TD CLASS=\"dddefault\">First room</TD><TD CLASS=\"dddefault\">Chris FUNG (<ABBR title=\"Primary\">P</ABBR>)</TD></TR></TABLE><TABLE CLASS=\"datadisplaytable\" SUMMARY=\"This layout table is used to present the schedule course detail\" cellspacing=\"0\" cellpadding=2><CAPTION class=\"captiontext\">Sci, Tech & Soc for Computing - AIS 3301 - T65</CAPTION><TR><TH COLSPAN=\"2\" CLASS=\"ddlabel\" scope=\"row\" >Associated Term:</TH><TD CLASS=\"dddefault\">Semester A 2014/15</TD></TR><TR><TH COLSPAN=\"2\" CLASS=\"ddlabel\" scope=\"row\" ><ACRONYM title=\"Course Reference Number\">CRN</ACRONYM>:</TH><TD CLASS=\"dddefault\">25708</TD></TR><TR><TH COLSPAN=\"2\" CLASS=\"ddlabel\" scope=\"row\" >Status:</TH><TD CLASS=\"dddefault\">Registered on Jul 10, 2014</TD></TR><TR><TH COLSPAN=\"2\" CLASS=\"ddlabel\" scope=\"row\" >Assigned Instructor:</TH><TD CLASS=\"dddefault\">Shu Chiu TSUN</TD></TR><TR><TH COLSPAN=\"2\" CLASS=\"ddlabel\" scope=\"row\" >Grade Mode:</TH><TD CLASS=\"dddefault\">Letter grade</TD></TR><TR><TH COLSPAN=\"2\" CLASS=\"ddlabel\" scope=\"row\" >Credits:</TH><TD CLASS=\"dddefault\"> 0.000</TD></TR><TR><TH COLSPAN=\"2\" CLASS=\"ddlabel\" scope=\"row\" >Level:</TH><TD CLASS=\"dddefault\">Bachelor's Degree</TD></TR><TR><TH COLSPAN=\"2\" CLASS=\"ddlabel\" scope=\"row\" >Campus:</TH><TD CLASS=\"dddefault\">Main Campus</TD></TR></TABLE><TABLE CLASS=\"datadisplaytable\" SUMMARY=\"This table lists the scheduled meeting times and assigned instructors for this class..\" cellspacing=\"0\" cellpadding=2><CAPTION class=\"captiontext\">Scheduled Meeting Times</CAPTION><TR><TH CLASS=\"ddheader\" scope=\"col\" >Type</TH><TH CLASS=\"ddheader\" scope=\"col\" >Time</TH><TH CLASS=\"ddheader\" scope=\"col\" >Days</TH><TH CLASS=\"ddheader\" scope=\"col\" >Where</TH><TH CLASS=\"ddheader\" scope=\"col\" >Date Range</TH><TH CLASS=\"ddheader\" scope=\"col\" >Schedule Type</TH><TH CLASS=\"ddheader\" scope=\"col\" >Instructors</TH></TR><TR><TD CLASS=\"dddefault\">Class</TD><TD CLASS=\"dddefault\">8:30 pm - 10:20 pm</TD><TD CLASS=\"dddefault\">M</TD><TD CLASS=\"dddefault\">Academic 1 Y5-203</TD><TD CLASS=\"dddefault\">Sep 01, 2014 - Nov 29, 2014</TD><TD CLASS=\"dddefault\">First room</TD><TD CLASS=\"dddefault\">Shu Chiu TSUN (<ABBR title=\"Primary\">P</ABBR>)</TD></TR></TABLE><BR>";
		File temp = File.createTempFile("courses", null);
		FileWriter fw = new FileWriter(temp);
		fw.write(html);
		fw.close();
		
		String output1 = "Code: AIS 3301 - C61\n"
				+"Name: Sci, Tech & Soc for Computing\n"
				+"Instructor: Chris FUNG\n"
				+"Venue: Academic 1 LT-6\n"
				+"Time: 06:30 PM - 08:20 PM\n"
				+"Weekday: Monday\n";
		String output2 = "Code: AIS 3301 - T65\n"
				+"Name: Sci, Tech & Soc for Computing\n"
				+"Instructor: Shu Chiu TSUN\n"
				+"Venue: Academic 1 Y5-203\n"
				+"Time: 08:30 PM - 10:20 PM\n"
				+"Weekday: Monday\n";
	
		ArrayList<CourseTO> result = impl.getCourses(temp);

		for(CourseTO to : result){
			assertEquals((to.toString().equals(output1) || to.toString().equals(output2)), true);
		}
	}

	//Test GetCourses With corrupt file
	//Test with pre-condition: all the previous functions are correct
	@Test
	public void testGetCoursesWithCorruptedFile() throws Exception{
		ByteArrayOutputStream outContent = new ByteArrayOutputStream();
		System.setOut(new PrintStream(outContent));
		String html = "<TABLis layout table is used to present the schedule course detail\" cellspacing=\"0\" cellpadding=2><CAPTION class=\"captiontext\">Sci, Tech & Soc for Computing - AIS 3301 - C61</CAPTION><TR><TH COLSPAN=\"2\" CLASS=\"ddlabel\" scope=\"row\" >Associated Term:</TH><TD CLASS=\"dddefault\">Semester A 2014/15</TD></TR><TR><TH COLSPAN=\"2\" CLASS=\"ddlabel\" scope=\"row\" ><ACRONYM title=\"Course Reference Number\">CRN</ACRONYM>:</TH><TD CLASS=\"dddefault\">43870</TD></TR><TR><TH COLSPAN=\"2\" CLASS=\"ddlabel\" scope=\"row\" >Status:</TH><TD CLASS=\"dddefault\">Registered on Jul 10, 2014</TD></TR><TR><TH COLSPAN=\"2\" CLASS=\"ddlabel\" scope=\"row\" >Assigned Instructor:</TH><TD CLASS=\"dddefault\">Chris FUNG</TD></TR><TR><TH COLSPAN=\"2\" CLASS=\"ddlabel\" scope=\"row\" >Grade Mode:</TH><TD CLASS=\"dddefault\">Letter grade</TD></TR><TR><TH COLSPAN=\"2\" CLASS=\"ddlabel\" scope=\"row\" >Credits:</TH><TD CLASS=\"dddefault\"> 3.000</TD></TR><TR><TH COLSPAN=\"2\" CLASS=\"ddlabel\" scope=\"row\" >Level:</TH><TD CLASS=\"dddefault\">Bachelor's Degree</TD></TR><TR><TH COLSPAN=\"2\" CLASS=\"ddlabel\" scope=\"row\" >Campus:</TH><TD CLASS=\"dddefault\">Main Campus</TD></TR></TABLE><TABLE CLASS=\"datadisplaytable\" SUMMARY=\"This table lists the scheduled meeting times and assigned instructors for this class..\" cellspacing=\"0\" cellpadding=2><CAPTION class=\"captiontext\">Scheduled Meeting Times</CAPTION><TR><TH CLASS=\"ddheader\" scope=\"col\" >Type</TH><TH CLASS=\"ddheader\" scope=\"col\" >Time</TH><TH CLASS=\"ddheader\" scope=\"col\" >Days</TH><TH CLASS=\"ddheader\" scope=\"col\" >Where</TH><TH CLASS=\"ddheader\" scope=\"col\" >Date Range</TH><TH CLASS=\"ddheader\" scope=\"col\" >Schedule Type</TH><TH CLASS=\"ddheader\" scope=\"col\" >Instructors</TH></TR><TR><TD CLASS=\"dddefault\">Class</TD><TD CLASS=\"dddefault\">6:30 pm - 8:20 pm</TD><TD CLASS=\"dddefault\">M</TD><TD CLASS=\"dddefault\">Academic 1 LT-6</TD><TD CLASS=\"dddefault\">Sep 01, 2014 - Nov 29, 2014</TD><TD CLASS=\"dddefault\">First room</TD><TD CLASS=\"dddefault\">Chris FUNG (<ABBR title=\"Primary\">P</ABBR>)</TD></TR></TABLE><TABLE CLASS=\"datadisplaytable\" SUMMARY=\"This layout table is used to present the schedule course detail\" cellspacing=\"0\" cellpadding=2><CAPTION class=\"captiontext\">Sci, Tech & Soc for Computing - AIS 3301 - T65</CAPTION><TR><TH COLSPAN=\"2\" CLASS=\"ddlabel\" scope=\"row\" >Associated Term:</TH><TD CLASS=\"dddefault\">Semester A 2014/15</TD></TR><TR><TH COLSPAN=\"2\" CLASS=\"ddlabel\" scope=\"row\" ><ACRONYM title=\"Course Reference Number\">CRN</ACRONYM>:</TH><TD CLASS=\"dddefault\">25708</TD></TR><TR><TH COLSPAN=\"2\" CLASS=\"ddlabel\" scope=\"row\" >Status:</TH><TD CLASS=\"dddefault\">Registered on Jul 10, 2014</TD></TR><TR><TH COLSPAN=\"2\" CLASS=\"ddlabel\" scope=\"row\" >Assigned Instructor:</TH><TD CLASS=\"dddefault\">Shu Chiu TSUN</TD></TR><TR><TH COLSPAN=\"2\" CLASS=\"ddlabel\" scope=\"row\" >Grade Mode:</TH><TD CLASS=\"dddefault\">Letter grade</TD></TR><TR><TH COLSPAN=\"2\" CLASS=\"ddlabel\" scope=\"row\" >Credits:</TH><TD CLASS=\"dddefault\"> 0.000</TD></TR><TR><TH COLSPAN=\"2\" CLASS=\"ddlabel\" scope=\"row\" >Level:</TH><TD CLASS=\"dddefault\">Bachelor's Degree</TD></TR><TR><TH COLSPAN=\"2\" CLASS=\"ddlabel\" scope=\"row\" >Campus:</TH><TD CLASS=\"dddefault\">Main Campus</TD></TR></TABLE><TABLE CLASS=\"datadisplaytable\" SUMMARY=\"This table lists the scheduled meeting times and assigned instructors for this class..\" cellspacing=\"0\" cellpadding=2><CAPTION class=\"captiontext\">Scheduled Meeting Times</CAPTION><TR><TH CLASS=\"ddheader\" scope=\"col\" >Type</TH><TH CLASS=\"ddheader\" scope=\"col\" >Time</TH><TH CLASS=\"ddheader\" scope=\"col\" >Days</TH><TH CLASS=\"ddheader\" scope=\"col\" >Where</TH><TH CLASS=\"ddheader\" scope=\"col\" >Date Range</TH><TH CLASS=\"ddheader\" scope=\"col\" >Schedule Type</TH><TH CLASS=\"ddheader\" scope=\"col\" >Instructors</TH></TR><TR><TD CLASS=\"dddefault\">Class</TD><TD CLASS=\"dddefault\">8:30 pm - 10:20 pm</TD><TD CLASS=\"dddefault\">M</TD><TD CLASS=\"dddefault\">Academic 1 Y5-203</TD><TD CLASS=\"dddefault\">Sep 01, 2014 - Nov 29, 2014</TD><TD CLASS=\"dddefault\">First room</TD><TD CLASS=\"dddefault\">Shu Chiu TSUN (<ABBR title=\"Primary\">P</ABBR>)</TD></TR></TABLE><BR>";
		File temp = File.createTempFile("courses", null);
		FileWriter fw = new FileWriter(temp);
		fw.write(html);
		fw.close();
			
		ArrayList<CourseTO> result = impl.getCourses(temp);
		assertEquals(result.size(), 0);
		assertEquals("FATAL ERROR: Something went wrong, the file is corrupted!\n", outContent.toString());
		System.setOut(System.out);
		outContent.close();
	}

	
}
